﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NDF.Serialization.Json;
using NDF.Serialization.Json.Converters;
using NDF.Utilities;
using System;
using System.Globalization;

namespace NDF.Tests.Framework.Jsonable
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            //JsonSerializerSettings settings = JsonConvert.DefaultSettings();

            //Console.WriteLine(settings);

            Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.MonthDayPattern);
            Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.YearMonthPattern);
            Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.RFC1123Pattern);
            Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.SortableDateTimePattern);
            Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.UniversalSortableDateTimePattern);
        }

        [TestMethod]
        public void TestMethod2()
        {
            var obj = new { ID = 1, Name = "张三", CreateDate = Convert.ToDateTime("0001/01/01 23:45:21.123") };
            Console.WriteLine(obj.ToJson());
            Console.WriteLine(obj.ToJson(DateTimeConverters.Normal));
            Console.WriteLine(obj.ToJson(DateTimeConverters.GeneralDate));
            Console.WriteLine(obj.ToJson(DateTimeConverters.LongDate));
            Console.WriteLine(obj.ToJson(DateTimeConverters.LongTime));
            Console.WriteLine(obj.ToJson(DateTimeConverters.FullDateTime));
            Console.WriteLine(obj.ToJson(DateTimeConverters.ShortDate));
            Console.WriteLine(obj.ToJson(DateTimeConverters.ShortTime));
            Console.WriteLine(obj.ToJson(DateTimeConverters.MonthDay));
            Console.WriteLine(obj.ToJson(DateTimeConverters.YearMonth));
            Console.WriteLine(obj.ToJson(DateTimeConverters.RFC1123DateTime));
            Console.WriteLine(obj.ToJson(DateTimeConverters.SortableDateTime));
            Console.WriteLine(obj.ToJson(DateTimeConverters.UniversalSortableDateTime));
            Console.WriteLine(obj.ToJson(DateTimeConverters.IsoDateTime));
            Console.WriteLine(obj.ToJson(DateTimeConverters.JavaScriptDateTime));
        }


        [TestMethod]
        public void TestMethod3()
        {
            User user = new User { ID = 1, Name = "张三", CreateDate = DateTime.Now };
            string json = user.ToJson();
            //var settings = new Newtonsoft.Json.JsonSerializerSettings();
            ////settings.Converters.Add(DateTimeConverters.IsoDateTime);
            JsonSerializer serializer = new JsonSerializer();

            var obj = serializer.Deserialize<User>(json);

            Console.WriteLine(obj.CreateDate);
            Console.WriteLine(user);
        }



        [TestMethod]
        public void TestMethod4()
        {
            //DateTime d = DateTime.MinValue;
            //Console.WriteLine(d);

            Console.WriteLine(DateTimeOffset.MinValue);
        }

        [TestMethod]
        public void TestMethod5()
        {
            var obj = new { CreateDate = DateTime.Now };
            Console.WriteLine(obj.ToJson());
        }
    }
    

    public class User
    {
        public int ID { get; set; }

        public string Name { get; set; }

        public DateTime CreateDate { get; set; }
    }
}
